import 'package:apple_style_wechat/global/constants.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';

enum ActionItems { GROUP_CHAT, ADD_CONTACT, QR_SCAN, PAYMENT }

class WechatPage extends StatefulWidget {
  @override
  _WechatPageState createState() => _WechatPageState();
}

class _WechatPageState extends State<WechatPage> {
  List<Widget> _actions;
  Widget _buildPopupMenuItem(int iconName, String title) {
    return Row(
      mainAxisSize: MainAxisSize.min,
      children: <Widget>[
        Icon(IconData(iconName, fontFamily: Constants.IconFontFamily),
            size: 22.0, color: const Color(AppColors.AppBarPopMenuTextColor)),
        SizedBox(width: 15.0),
        Text(
          title,
          style: TextStyle(
            fontWeight: FontWeight.bold,
            color: const Color(AppColors.AppBarPopMenuTextColor),
          ),
        ),
      ],
    );
  }

  @override
  void initState() {
    super.initState();
    _actions = <Widget>[
      IconButton(
        icon: Icon(IconData(0xe603, fontFamily: Constants.IconFontFamily),
            size: 22.0),
        onPressed: () => print('点击搜索按钮'),
      ),
      PopupMenuButton(
        padding: EdgeInsets.all(0.0),
        offset: Offset(0, 80.0),
        icon: Icon(IconData(0xe61c, fontFamily: Constants.IconFontFamily),
            size: 22.0),
        onSelected: (value) => print('$value'),
        itemBuilder: (BuildContext context) {
          return <PopupMenuItem<ActionItems>>[
            PopupMenuItem(
              child: _buildPopupMenuItem(0xe604, '发起群聊'),
              value: ActionItems.GROUP_CHAT,
            ),
            PopupMenuItem(
              child: _buildPopupMenuItem(0xe613, '添加朋友'),
              value: ActionItems.ADD_CONTACT,
            ),
            PopupMenuItem(
              child: _buildPopupMenuItem(0xe6a2, '扫一扫'),
              value: ActionItems.QR_SCAN,
            ),
            PopupMenuItem(
              child: _buildPopupMenuItem(0xe62b, '收付款'),
              value: ActionItems.PAYMENT,
            ),
          ];
        },
      ),
    ];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('微信'),
        elevation: 0.0,
        centerTitle: true,
        actions: _actions,
      ),
      body: _ConversationListView(),
    );
  }
}

class _ConversationListView extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.indigo,
    );
  }
}
